package com.bestcem.xm.user.config.properties;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户登录注册类邮件主题和通知中心标题映射
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/6 17:24
 */
@Component
@Data
public class MailSubjectNotifyTitleEnumProperties {

    @Autowired
    private SettingProperties settingProperties;

    private Map<String, String> notifyMap;

    @PostConstruct
    private void initMap() {
        notifyMap = new HashMap<>(16);
        notifyMap.put(NotifyTitleEnum.USER_ACTIVATION.key, NotifyTitleEnum.USER_ACTIVATION.value);
        notifyMap.put(settingProperties.getBestcemEmailSign() + NotifyTitleEnum.RESET_PASSWORD.key, NotifyTitleEnum.RESET_PASSWORD.value);
        notifyMap.put(settingProperties.getBestcemEmailSign() + NotifyTitleEnum.MAIL_VERIFY.key, NotifyTitleEnum.MAIL_VERIFY.value);
        notifyMap.put(settingProperties.getBestcemEmailSign() + NotifyTitleEnum.REGISTER.key, NotifyTitleEnum.REGISTER.value);

        notifyMap.put("[" + settingProperties.getXmName() + NotifyTitleEnum.APPLY_INFO.key + "]",
                "[" + settingProperties.getXmName() + NotifyTitleEnum.APPLY_INFO.value + "]");
        notifyMap.put("[" + settingProperties.getXmName() + NotifyTitleEnum.FREE_APPLY_INFO.key + "]",
                "[" + settingProperties.getXmName() + NotifyTitleEnum.FREE_APPLY_INFO.value + "]");
        notifyMap.put(settingProperties.getBestcemEmailSign() + NotifyTitleEnum.OM_USER_CREATE.key,
                settingProperties.getBestcemEmailSign() + NotifyTitleEnum.OM_USER_CREATE.value);
        notifyMap.put(NotifyTitleEnum.OM_USER_RESET_PASSWORD.key, NotifyTitleEnum.OM_USER_RESET_PASSWORD.value);
        notifyMap.put(NotifyTitleEnum.QDES_LIMIT.key, NotifyTitleEnum.QDES_LIMIT.value);
        notifyMap.put(NotifyTitleEnum.QDES_USED.key, NotifyTitleEnum.QDES_USED.value);
        notifyMap.put(NotifyTitleEnum.ANSWER_SHEET_LIMIT.key, NotifyTitleEnum.ANSWER_SHEET_LIMIT.value);
        notifyMap.put(NotifyTitleEnum.ANSWER_SHEET_USED.key, NotifyTitleEnum.ANSWER_SHEET_USED.value);
        notifyMap.put(settingProperties.getBestcemSmsSign() + NotifyTitleEnum.PACKAGE_ARRIVAL.key, NotifyTitleEnum.PACKAGE_ARRIVAL.value);
        notifyMap.put(settingProperties.getBestcemSmsSign() + NotifyTitleEnum.PACKAGE_EXPIRED.key, NotifyTitleEnum.PACKAGE_EXPIRED.value);
    }

    /**
     * 检索主题是否在指定的枚举中
     *
     * @param subject 主题内容
     * @return boolean 是否在指定的枚举中
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/06/06 17:59
     */
    public boolean containsSubject(String subject) {
        return notifyMap.containsKey(subject);
    }

    /**
     * 根据主题获取对应的title信息
     *
     * @param subject 主题内容
     * @return java.lang.String title内容
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/06/06 18:01
     */
    public String getTitle(String subject) {
        return notifyMap.get(subject);
    }

    @AllArgsConstructor
    @Getter
    public enum NotifyTitleEnum {
        /**
         * 用户登录注册类 邮件主题和通知中心标题映射枚举
         */
        USER_ACTIVATION("用户激活", "激活", "用户激活"),
        RESET_PASSWORD("重置密码", "找回密码", "重置密码无法携带org_id 有可能会有多个公司，不能归属于一个"),
        MAIL_VERIFY("邮箱验证", "重置邮箱", ""),
        REGISTER("企业账号开通", "注册成功", ""),
        APPLY_INFO("申请信息", "申请信息", "销售预约线索"),
        FREE_APPLY_INFO("申请信息-免费版", "申请信息-免费版", "销售注册线索"),
        OM_USER_CREATE("", "", "om 用户创建"),
        OM_USER_RESET_PASSWORD("用户密码重置", "用户密码重置", "om 重置密码"),
        QDES_LIMIT("【倍市得CEM】项目数到限额", "问卷限额", "项目限额"),
        QDES_USED("【倍市得CEM】项目数即将到达限额", "问卷用量", "项目即将限额"),
        ANSWER_SHEET_LIMIT("【倍市得CEM】答卷数到限额", "答卷限额", "答卷限额"),
        ANSWER_SHEET_USED("【倍市得CEM】答卷数即将到达限额", "答卷用量", "答卷即将限额"),
        PACKAGE_ARRIVAL(" 套餐即将过期", "版本临期", "套餐临期"),
        PACKAGE_EXPIRED(" 套餐已过期", "版本到期", "套餐过期"),
        ;

        private String key;
        private String value;
        private String desc;

    }

}
